<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>办公OA系统</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <style>
        body{
            background: #f2f2f2;
            background-size: cover;
        }
        .oa-container{
            position: absolute;
            width: 400px;
            height: 350px;
            top: 50%;
            left: 50%;
            padding: 20px;
            margin-left: -200px;
            margin-top: -175px;
        }
    </style>
</head>
<body>
<div class="oa-container" >
    <h1 style="text-align: center;margin-bottom: 20px">办公OA系统</h1>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="login">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="resources/layui/layui.js"></script>
<script>
    layui.form.on("submit(login)", function (formData) {
        console.log(formData);
        layui.$.ajax({
            url: "/check_login",
            data: formData.field,
            type: "POST",
            //json 服务器返回json
            dataType: "json",
            success: function (json) {
                console.log(json);
                if (json.code == "0") {
                    //layui.layer.msg("登录成功");

                    //跳转url
                    window.location.href = json.redirect_url;
                } else {
                    layui.layer.msg(json.message);
                }
            }
        });
        return false; //true表示提交 false表示阻止提交  一定要用false 否则ajax失效
    })
</script>
</body>

</html>